package com.qianclass.talklive.app.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.qianclass.talklive.R;

/**
 * Created by Administrator on 2017/6/16.
 */

public class OperationMenuAdapter extends BaseAdapter {

    private Context mContext;
    private String[] mOperationMenus;
    private int mItemCounts;

    public OperationMenuAdapter(Context context, String[] operationMenus, int itemCounts) {
        mContext = context;
        mOperationMenus = operationMenus;
        mItemCounts = itemCounts;
    }

    public void updateData(String[] operationMenus){
        mOperationMenus = operationMenus;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mItemCounts;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_operation_menu, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.tvOperation.setText(mOperationMenus[position]);

        return convertView;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    class ViewHolder{
        TextView tvOperation;

        ViewHolder(View view){
            tvOperation = (TextView) view.findViewById(R.id.tv_operation);
        }
    }
}
